const router = require("express")();
module.exports = router;

const db = require("../core/Data");
const User = require("../core/User");


const PAGE_CREATE = "/create.html";
const PAGE_LOGIN = "/login.html";
const _PAGE_CREATE = "." + PAGE_CREATE;
const _PAGE_LOGIN = "." + PAGE_LOGIN;

router.get(PAGE_LOGIN, User.middle_checker(false), (req, res, next) => {
    APP.infoLog('handler', "page_login");
    if (req.user) res.redirect(_PAGE_CREATE);
    else next();
});
router.get(PAGE_CREATE, User.middle_checker(false), (req, res, next) => {
    APP.infoLog('handler', "page_create");
    if (!req.user) res.redirect(_PAGE_LOGIN);
    else next();
});

router.use("/", require("express").static("./public"));